from django.shortcuts import render
import datetime
# Create your views here.

from rest_framework.generics import ListAPIView
from . import models
from rest_framework.permissions import IsAuthenticated
from .serializers import UserCouponModelSerializer

class CouponView(ListAPIView):
    permission_classes = [IsAuthenticated,]
    serializer_class = UserCouponModelSerializer
    def get_queryset(self):
        now = datetime.datetime.now()
        queryset = models.UserCoupon.objects.filter(
            is_show=True, is_deleted=False,
            is_use=False,
            user_id=self.request.user.id,
            start_time__lte=now,

        )
        #<class 'django.db.models.query.QuerySet'>

        # print(type(queryset))
        # from django.db.models.query import QuerySet
        #
        #
        # for obj in queryset:
        #     timer = obj.coupon.timer
        #     end_time = obj.start_time + datetime.timedelta(days=timer)
        #     if now.timestamp() <= end_time.timestamp():
        #         pass
        return queryset
